import UHFDriver
import re
import time
import binascii

from pyrfid.DataProtocol.Driver.JTEDriver import JTEDriver


class JTEUSBDriver(JTEDriver):
    
    MAX_READ_PAGES = 16
    MAX_EXECUTION_TIME = 1
    MULTIPLE_WORD_ACCESS = False
    __sessionManager = object

    def __init__(self, level):
        super(JTEDriver, self).__init__(level, False, self.MAX_EXECUTION_TIME)
        
    def _readCommand(self, tagId, executeBankType, startOnWordAddress, length):
        print "readCommand"
        responseArray = list()
        print "2222~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        if length < self.MAX_READ_PAGES:            
            response = super(JTEUSBDriver, self)._readCommand(tagId, executeBankType, startOnWordAddress, length)
            responseArray.append(response)
        else:
            executeReadStartAddress = int()
            for startReadIndex in range(length/self.MAX_READ_PAGES):
                #access Command
                executeReadStartAddress = startOnWordAddress + (startReadIndex * self.MAX_READ_PAGES)
                responseArray.append(super(JTEUSBDriver, self)._readCommand(tagId, executeBankType, executeReadStartAddress, self.MAX_READ_PAGES))
            #until not read space check
            otherReadWordSize = length % self.MAX_READ_PAGES
            if otherReadWordSize != 0:
                executeReadStartAddress = executeReadStartAddress + self.MAX_READ_PAGES
                responseArray.append(super(JTEUSBDriver, self)._readCommand(tagId, executeBankType, executeReadStartAddress, otherReadWordSize))
        
        response = str()
        for tempResponse in responseArray:
            response += tempResponse
        
        return response
    